//package io.renren.modules.upk.controller;
//
//import com.alibaba.fastjson.JSONObject;
//
//import io.renren.common.utils.R;
//import org.apache.catalina.WebResource;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.multipart.MultipartHttpServletRequest;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.Random;
//import com.sun.jersey.api.client.Client;
//import com.sun.jersey.api.client.WebResource;
//
//
//@Controller
//@RequestMapping("/upload")
//public class UploadController {
//
//
//	@RequestMapping("/uploadPic.do")
//	public R uploadPic(String fileName, HttpServletRequest request, PrintWriter out) throws IOException {
//		MultipartHttpServletRequest mr = (MultipartHttpServletRequest) request;
//		MultipartFile mf = mr.getFile(fileName);
//		byte[] fbyte = mf.getBytes();
//		String tFileName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
//		Random random = new Random();
//		for (int i = 0; i < 3; i++) {
//			tFileName = tFileName + random.nextInt(10);
//		}
//		String oriFileName = mf.getOriginalFilename();
//		//后缀名
//		String suffix = oriFileName.substring(oriFileName.lastIndexOf("."));
//		//相对路径
//		String relativePath = "/upload/" + tFileName + suffix;
//		//创建Jersey客户端
//		Client client = Client.create();
//		//获得web资源
//		WebResource wr = client.resource(realPath);
//		//上传
//		wr.put(fbyte);
//
//		//做ajax的程序离不开json，如果返回值数量多于等于2个请用json
//		//创建json对象
//		JSONObject jo = new JSONObject();
//		//往json对象中放值，和map类似
//		jo.accumulate("realPath", realPath);
//		jo.accumulate("relativePath", relativePath);
//		//调用json对象的toString方法把对象变成json格式的字符串
//		//{"realPath":"http://loalhost..", "relativePath":"/upload/..."}
//		String result = jo.toString();
//		out.write(result);
//	}
//}
//
//
